﻿
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports Zen.Barcode
Imports System.Collections.Generic
Imports System.Drawing.Drawing2D
Imports System.Drawing
Imports VSModel
Imports Cls_Common

Partial Class Page_Product_BarCode
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then

            If Not Request("Id") Is Nothing Then
                Dim _ProductId As Integer = Request("Id")
                Using _data As New VSEntities
                    Dim p = (From q In _data.Products Where q.ProductId = _ProductId Select q).FirstOrDefault
                    If Not p Is Nothing Then
                        GenBarCode(p.Code.ToString.Trim())

                        imgBarcode.ImageUrl = MainDomain & "Uploads/BarCode/" & p.Code & ".jpg"
                        ltrName.Text = p.Code


                    End If
                End Using

            End If
        End If
    End Sub

    Protected Sub GenBarCode(ByVal _Barcode As String)
        Dim symbology As BarcodeSymbology = BarcodeSymbology.Code39C
        symbology = BarcodeSymbology.Code39C

        Dim scale As Integer = 1
        Dim bdf As Code39BarcodeDraw = BarcodeDrawFactory.Code39WithoutChecksum
        Dim Newsimages As System.Drawing.Image = bdf.Draw(_Barcode, 50, 1)

        Dim Width = Newsimages.Width
        Dim Height = Newsimages.Height


        Dim thumbnailBitmap = New Bitmap(Width, Height)

        Dim thumbnailGraph = Graphics.FromImage(thumbnailBitmap)
        thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality
        thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality
        thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic


        Dim imageRectangle = New Rectangle(0, 0, Width, Height + 10)
        thumbnailGraph.DrawImage(Newsimages, imageRectangle)
        Dim path2Save As String = Server.MapPath("~/Uploads").ToString & "/BarCode/" & _Barcode & ".jpg"

        thumbnailBitmap.Save(path2Save)
    End Sub



End Class
